package com.ruihu.admin.module.business.task.domain.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.task.domain.dto.SubtaskDefectAddDTO;
import com.ruihu.admin.module.business.task.domain.dto.SubtaskDefectDTO;
import com.ruihu.admin.module.business.task.domain.dto.SubtaskDefectUpdateDTO;
import lombok.Data;

import java.util.Objects;

/**
 * [ 电芯缺陷关系表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-09-22 13:42:27
 * @since JDK1.8
 */

@Data
@TableName("t_subtask_defect")
public class SubtaskDefectEntity extends BaseEntity {


    /**
     * sub_task_id
     */
    private Long subTaskId;

    /**
     * defect_type_id
     */
    private Long defectTypeId;

    /**
     * revision
     */
    private Integer revision;


    /**
     * create_by
     */
    private Long createBy;


    /**
     * update_by
     */
    private Long updateBy;

    public static SubtaskDefectEntity convertToSubtaskDefectEntity(SubtaskDefectAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        SubtaskDefectEntity entity = new SubtaskDefectEntity();
        entity.setSubTaskId(addDTO.getSubTaskId());
        entity.setDefectTypeId(addDTO.getDefectTypeId());
        return entity;
    }


    public static SubtaskDefectEntity convertToSubtaskDefectEntity(SubtaskDefectUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        SubtaskDefectEntity entity = new SubtaskDefectEntity();
        entity.setId(updateDTO.getId());
        entity.setSubTaskId(updateDTO.getSubTaskId());
        entity.setDefectTypeId(updateDTO.getDefectTypeId());
        return entity;
    }

    public static SubtaskDefectEntity convertToSubtaskDefectEntity(SubtaskDefectDTO dto) {
        if (dto == null) {
           return null;
        }

        SubtaskDefectEntity entity = new SubtaskDefectEntity();
        entity.setId(dto.getId());
        entity.setSubTaskId(dto.getSubTaskId());
        entity.setDefectTypeId(dto.getDefectTypeId());
        entity.setRevision(dto.getRevision());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateTime(dto.getUpdateTime());
        return entity;
    }

    public static SubtaskDefectEntity copyIgnoreNullAndEmpty(SubtaskDefectEntity sourceEntity, SubtaskDefectEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (Objects.nonNull(sourceEntity.getSubTaskId())) {
           destEntity.setSubTaskId(sourceEntity.getSubTaskId());
        }
        if (Objects.nonNull(sourceEntity.getDefectTypeId())) {
           destEntity.setDefectTypeId(sourceEntity.getDefectTypeId());
        }
        if (Objects.nonNull(sourceEntity.getRevision())) {
           destEntity.setRevision(sourceEntity.getRevision());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
           destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getCreateBy())) {
           destEntity.setCreateBy(sourceEntity.getCreateBy());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
           destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateBy())) {
           destEntity.setUpdateBy(sourceEntity.getUpdateBy());
        }
        return destEntity;
    }
}
